package com.itheima.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Description: DemoInterceptor 拦截器快速入门
 * @Author: HH
 * @Date: 2025/4/20 16:00
 **/
@Slf4j
@Component
public class DemoInterceptor implements HandlerInterceptor {
    @Override // 拦截器前置处理, 请求资源方法前运行，返回true表示放行，false表示拦截
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("拦截器前置处理...");
        return false;
    }

    @Override // 拦截器后置处理, 请求资源方法后运行
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("拦截器后置处理...");
    }

    @Override // 拦截器最终运行
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("拦截器最终运行...");
    }
}
